package com.bysj.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bysj.entity.User;
import com.bysj.fenye.pagevo.UserPageVO;
import com.bysj.service.UserService;
import com.bysj.service.impl.UserServiceImpl;
import com.ywb.messageDigest.MD5Digest;

public class UserServlet extends HttpServlet {
	private UserService userService = new UserServiceImpl();
	private UserPageVO pagevo=new UserPageVO(10);
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String m=request.getParameter("m");
		String method=request.getParameter("method");
		if("pre".equals(method)){
			this.pagevo.setPrevious();
		}else if("next".equals(method)){
			this.pagevo.setNext();
		}else if("last".equals(method)){
			this.pagevo.setLast();
		}else if("index".equals(method)){
			String ind=request.getParameter("ind");
			this.pagevo.setIndex(Integer.parseInt(ind.trim()));
		}else{
			this.pagevo.setFirst();
		}
		if("AllUser".equals(m)){
			request.getSession().setAttribute("userList", pagevo);
			request.getRequestDispatcher("../user/AllUser.jsp").forward(request, response);
		}else if("DetailUserInfo".equals(m)){
			Integer userId=Integer.parseInt(request.getParameter("userId"));
			User us=new User();
			us.setId(userId);
			User u=userService.queryUser(us);
			request.getSession().setAttribute("userById", u);
			request.getRequestDispatcher("../user/DetailUserInfo.jsp").forward(request, response);
		}else if("DeleteUser".equals(m)){
			Integer userId=Integer.parseInt(request.getParameter("userId"));
			User us=new User();
			us.setId(userId);
			userService.delUser(us);
			request.getSession().setAttribute("userList", pagevo);
			request.getRequestDispatcher("../user/AllUser.jsp").forward(request, response);
		}
	}

}
